package com.rocker.graduation.controller;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rocker.graduation.entity.ErrorBean;
import com.rocker.graduation.service.testService;
import com.rocker.graduation.util.FileUtils;

@Controller
@RequestMapping("/test")
public class testConnection {
	@Autowired
	testService testService;
	
	@RequestMapping(value="/test")
	@ResponseBody
	public ErrorBean test4Connection(@RequestBody ErrorBean errorBean){
		System.out.println(errorBean.getSuccess());
		return errorBean;
	}
	
	@RequestMapping(value="/testImage")
	public void test4Image(HttpServletRequest request, HttpServletResponse response){
		response.setContentType("image/jpg");
		try {
			//BufferedImage bImage = ImageIO.read(new ByteArrayInputStream(testService.getByteArray().getCategoryEntity()));
			BufferedImage bImage = FileUtils.markImageLogo(testService.getByteArray().getCategoryEntity());
			ImageIO.write(bImage, "JPEG", response.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
